"
). "This is a string."
The value of a string literal is an instance of the class
StringConstant
, which stores the string as a
sequence of UTF values, an optimized representation of 31-bit
Unicode/ISO 10646 values. Unicode allows ScriptX to represent
most international characters.
Strings can contain any characters, including single quotes, operators, and other characters that would be interpreted differently by ScriptX outside the string. The following strings contain character sequences that make them look like other ScriptX constructs:
"Is it a string? Yes, it's a string."
"-- A string with a comment in it"
"a string with an assignment := in it"
"a string with arithmetic in it: 4 + 4"
Strings can also include end-of-line characters; that is, strings can be spread over several lines. End-of-line characters are preserved in a string as newline characters:
"Jack and Jill
went up the hill
to fetch a pail of water"
Table 2-1 lists special characters that can be included in strings as escape sequences.
Characters |
Meaning |
---|---|
\r | return |
\n | new line |
\t | tab |
\" | double-quote |
\\ | backslash |
\<nnnn> | hexadecimal values for Unicode characters |
Note that ScriptX handles the problem of different implementations of the newline character (\n) on different platforms by forcing the newline character from all platforms to the value 13.
When the text string is compiled, ASCII special characters are converted into their internal equivalents, and are not displayed again as escape characters.
"a string with a \n return in it"
"a string with a
return in it"
Non-ASCII Unicode characters are represented as Unicode escape characters when they are printed to a stream, such as the Listener window.
-- \<2122> represents the trademark symbol ( )
"ScriptX\<2122> is a really awesome language"
"ScriptX\<2122> is a really awesome language"
At this time, the operating systems on which the Kaleida Media Player runs do not support the Unicode standard. Full support is expected in the future. In the interim, ScriptX maps common Unicode characters to platform-specific character sets. Characters are displayed correctly as the target of a text presenter, provided that the character is supported by the underlying system, and that an appropriate glyph is available in the display font.
ScriptX does not map platform-specific (non-ASCII) characters to their corresponding unicode characters. Representation of non-ASCII characters requires the use of escape sequences, as in the example above. Appendix B, "Unicode Escape Characters," contains a listing of many commonly used special characters and their hexadecimal Unicode values. For an explanation of Unicode and UTF encoding, see the "Text and Fonts" chapter of the ScriptX Components Guide.
StringConstant
. Instances of
String
and StringConstant
appear the
same in most operations, but functions or operators (such as
the comparison functions described on page 40) that are concerned with the
classes of those objects may differentiate between them.
When you attempt to modify a string constant, some operations
convert it automatically to a String
object, its
editable counterpart. These operations include string addition
and subtraction, described on page
43. Other operations require that you explicitly coerce
the string constant to a string. Coercion of objects from one
class to another is described in Chapter 3, "Working with Objects."
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.